package com.cmj.controller;

import com.cmj.domain.ResponseResult;
import com.cmj.domain.entity.Article;
import com.cmj.service.ArticleService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 文章表(Article)表控制层
 *
 * @author makejava
 * @since 2022-03-12 16:43:19
 */
@RestController
@RequestMapping("/article")
@Api(tags = "文章",description = "文章相关接口")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /***
     * 获取热门文章统计 前10条
     * @return 获取到的热门文章
     */
    @GetMapping("/hotArticleList")
    public ResponseResult<Article> hotArticleList(){
        return articleService.hotArticleList();
    }

    /***
     * 文章列表
     * @param pageNum 页数
     * @param pageSize 页大小
     * @param categoryId 分类id
     * @return ArticleListVo的文章列表
     */
    @GetMapping("/articleList")
    public ResponseResult articleList(Integer pageNum,Integer pageSize,Long categoryId){
        return articleService.articleList(pageNum,pageSize,categoryId);
    }

    /**
     * 点击后写入浏览量
     * @param id 文章id
     * @return 操作结果
     */
    @PutMapping("/updateViewCount/{id}")
    public ResponseResult updateViewCount(@PathVariable("id") Long id){
        return articleService.updateViewCount(id);
    }

    /***
     * 文章详情
     * @param id 文章id
     * @return Article文章详情
     */
    @GetMapping("/{id}")
    public ResponseResult getArticleDetail(@PathVariable("id") Long id){
        return articleService.getArticleDetail(id);
    }
}

